//
//  AddressBooksTableViewCell.m
//  MobileOffice
//
//  Created by jjkj on 16/10/24.
//  Copyright © 2016年 liaoningjujin. All rights reserved.
//

#import "AddressBooksTableViewCell.h"

@implementation AddressBooksTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier isLeader:(BOOL)isLeader{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        //scrollView
        _backScrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, 79)];
        _backScrollView.contentSize=CGSizeMake(IPHONE_WIDTH+120, 0);
        _backScrollView.pagingEnabled=YES;
        _backScrollView.bounces=NO;
        _backScrollView.delegate=self;
        _backScrollView.showsVerticalScrollIndicator=NO;
        _backScrollView.showsHorizontalScrollIndicator=NO;
        _backScrollView.userInteractionEnabled=YES;
        [self.contentView addGestureRecognizer:_backScrollView.panGestureRecognizer];
        [self.contentView addSubview:_backScrollView];
        
        _headImageView=[MyControl creatImageViewWithFrame:CGRectMake(10, 10, 60, 60) imageName:@""];
        _headImageView.layer.masksToBounds=YES;
        _headImageView.layer.cornerRadius=_headImageView.width/2;
        [_backScrollView addSubview:_headImageView];
        
        _statusImageView=[MyControl creatImageViewWithFrame:CGRectMake(34, 59, 46, 18) imageName:@"k_ic_ts_gcz.png"];
        [_backScrollView addSubview:_statusImageView];
        
        _statusButton=[UIButton buttonWithType:UIButtonTypeCustom];
        _statusButton.frame=CGRectMake(34, 55, 46, 28);
        _statusButton.titleLabel.font=FONT_12;
        [_statusButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_backScrollView addSubview:_statusButton];
        
        _nameLabel=[MyControl creatLabelWithFrame:CGRectMake(_headImageView.x+_headImageView.width+20, 20, IPHONE_WIDTH-(_headImageView.x+_headImageView.width+20)-8, 21) text:@""];
        [_backScrollView addSubview:_nameLabel];
        
        _jobLabel=[MyControl creatLabelWithFrame:CGRectMake(_nameLabel.x, _nameLabel.y+_nameLabel.height+10 ,_nameLabel.width, 21) text:@""];
        _jobLabel.textColor=[UIColor lightGrayColor];
        _jobLabel.font=FONT_13;
        [_backScrollView addSubview:_jobLabel];
        
        _lineLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, 79, IPHONE_WIDTH, 1)];
        _lineLabel.backgroundColor=BACKCOLOR_GRAY;
        [self.contentView addSubview:_lineLabel];
        
        UIView *msgView=[[UIView alloc]initWithFrame:CGRectMake(IPHONE_WIDTH, 0, 120, 80)];
        msgView.backgroundColor=[UIColor lightGrayColor];
        [_backScrollView addSubview:msgView];
        
        if (isLeader) {
            _msgButton=[UIButton buttonWithType:UIButtonTypeCustom];
            _msgButton.frame=CGRectMake(3, 22,36, 36);
            [_msgButton setBackgroundImage:[UIImage imageNamed:@"app@2x"] forState:UIControlStateNormal];
            [msgView addSubview:_msgButton];
            
            _phoneButton=[UIButton buttonWithType:UIButtonTypeCustom];
            _phoneButton.frame=CGRectMake(42, 22,36, 36);
            [_phoneButton setBackgroundImage:[UIImage imageNamed:@"bodadianhua@2x"] forState:UIControlStateNormal];
            [msgView addSubview:_phoneButton];
            
            _smsButton=[UIButton buttonWithType:UIButtonTypeCustom];
            _smsButton.frame=CGRectMake(81, 22,36, 36);
            [_smsButton setBackgroundImage:[UIImage imageNamed:@"fasongduanxin@2x"] forState:UIControlStateNormal];
            [msgView addSubview:_smsButton];
        }else{
            _msgButton=[UIButton buttonWithType:UIButtonTypeCustom];
            _msgButton.frame=CGRectMake(42, 22,36, 36);
            [_msgButton setBackgroundImage:[UIImage imageNamed:@"app@2x"] forState:UIControlStateNormal];
            [msgView addSubview:_msgButton];
        }
        
        UITapGestureRecognizer *tapGesture= [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapGestureClick)];
        [self.contentView addGestureRecognizer:tapGesture];
    }
    return self;
}

#pragma mark -手势的响应事件
- (void)tapGestureClick{
    if (_clickBlock) {
        _clickBlock(self.row);
    }
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    if (_myBlock) {
        _myBlock(_backScrollView);
    }
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
